package kit.edu.lego.gruppe3.levels.line.alternative;

import kit.edu.lego.gruppe3.ComponentsRepository;
import kit.edu.lego.gruppe3.LegoMain;
import kit.edu.lego.gruppe3.levels.LevelSelector;
import kit.edu.lego.gruppe3.levels.bridge.BridgeSolver;
import kit.edu.lego.gruppe3.levels.fallingBridge.FallingBridgeSolver;
import kit.edu.lego.gruppe3.levels.rollbridge.RollBridgeSolver;
import kit.edu.lego.gruppe3.levels.treeArea.TreeAreaSolver;
import lejos.nxt.LightSensor;
import lejos.robotics.navigation.DifferentialPilot;
import lejos.robotics.navigation.MoveListener;
import lejos.robotics.subsumption.*;

public class LineEndReached implements Behavior
{
	
	private boolean suppressed = true;
	private DifferentialPilot robot = ComponentsRepository.getInstance().getRobotPilot();
	LightSensor lightSensor = ComponentsRepository.getInstance().getLightSensor();
	MoveListener move;

	@Override
	public void action()
	{
		if ( ! RollBridgeSolver.isLevelCleared()){
			LegoMain.startRollBridge();
		} else {
			if (! BridgeSolver.isLevelCleared()){
				// move through door - bluetooth solver on!
			} else {
				if ( ! FallingBridgeSolver.isLevelCleared()){
					LegoMain.startBridge(); // has to be falling bridge!
				} else {
					LegoMain.startRollBridge();
				}
			}
		}
		
	}

	@Override
	public void suppress()
	{
		suppressed = !suppressed;
	}

	@Override
	public boolean takeControl()
	{
		return LevelSelector.getInstance().isLine() && 
		lightSensor.readValue() < ComponentsRepository.LIGHT_TRASHOLD &&
		!suppressed;
	}

}
